<template>
	<view>
		
		<!-- <my-search :bgColor="bgColor" @click="hanHan"></my-search> -->
		<!-- <my-search :bgColor="bgColor" @click="hanHan"></my-search> -->
		<my-search></my-search>
		
		<!-- <button type="default">uniapp中的按钮</button> -->
		<!-- <text>home页面</text> -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			
			<swiper-item v-for="(item,index) in swiperList" :key='index'>
				<!-- <navigator class="swiper-item" :url=" '/subpkg/goods-detail/goods-detail' "> -->
				
				<navigator class="swiper-item" :url=" `/subpkg/goods-detail/goods-detail?goods_id=${item.goods_id}` ">
					<image :src="item.image_src"></image>
				</navigator>
				
			</swiper-item>
			
		</swiper>
		
		
		<view class="nav-list">
			
			<view class="nav-item" v-for="(item,index) in navList" :key='index' @click="goCate(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
			
		</view>
		
		<view class="floor-list">
			
			<view class="floor-item" v-for="(item,index) in floorList" :key='index'>
				
				<image :src="item.floor_title.image_src" mode="" class="floor-item-title"></image>
				<view class="floor-img-box">
					
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" mode=""></image>
					</navigator>
					
					<view class="right-img-box">
						
						<navigator class="right-img-item" v-for="(item2,index2) in item.product_list" :key='index2 ' v-if="index2 !== 0" :url="item2.url">
							<image :src="item2.image_src" mode="" class="right-item-img"></image>
						</navigator>
						
					</view>
					
				</view>
				
			</view>
			
		</view>
		
	</view>
</template>

<script>
	
import { swiperdata,catitemesdata,floordata } from "@/api/home-request.js";
	
	export default {
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[],
				// bgColor:'#ccc'
			};
		},
		
		onLoad(){
			this.getSwiperData();
			// this.test();
			this.getCatitemsData();
			this.getFloorData(); 
		},
		
		methods:{
			// hanHan(){
			// 	console.log('hanhan');
			// },
			
			goCate(item) {
				if(item.name === '分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			
			
			// 发送网络数据请求
			async getSwiperData(){
				const {data:res} = await swiperdata();
				// console.log(result);
				// console.log(res);
				// if(res.meta.status !== 200);
				// return uni.$shouMsg();
				if(res.meta.status !== 200){
					return uni.showToast({
						title:'数据请求失败，请稍后',
						icon:'none'
					})
				};
				this.swiperList = res.message;
				// console.log(this.swiperList);
			},
			
			async getCatitemsData(){
				const {data:res} = await catitemesdata();
				// console.log(res);
				// if(res.meta.status !== 200) ;
				// return uni.$shouMsg();
				if(res.meta.status !== 200){
					return uni.showToast({
						title:'数据请求失败，请稍后',
						icon:'none'
					})
				};
				this.navList = res.message;
			},
			
			async getFloorData(){
				const {data:res} = await floordata();
				console.log(res);
				if(res.meta.status !== 200){
					return uni.showToast({
						title:'数据请求失败，请稍后',
						icon:'none'
					})
				};
				res.message.forEach(floor=>{
					floor.product_list.forEach(prod=>{
						prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1];
					})
				})
				this.floorList = res.message;
			},
			// goCate(item){
			// 	switch(item.name){
			// 		case '分类':
			// 		uni.navigateTo({
			// 			url:'/home/cate-Fenlei/'
			// 		});
			// 		break;
			// 		case '秒杀拍':
			// 		uni.navigateTo({
			// 			url:'/pages/cateTwo/cate-MiaoSha/cate-MiaoSha'
			// 		});
			// 		break;
			// 		case '超市购':
			// 		uni.navigateTo({
			// 			url:'/pages/cateTwo/cate-ChaoShi/cate-ChaoShi'
			// 		});
			// 		break;
			// 		case '母婴品':
			// 		uni.navigateTo({
			// 			url:'/pages/cateTwo/cate-MuYingPin/cate-MuYingPin'
			// 		});
			// 		break;
			// 	}
			// },
			test(){
				console.log('test');
				let obj = {
					nane:'tom',
					age:20
				};
				console.log(obj);
				let {name,age} = obj;
				console.log(name,age)
			}
		}
		
	}
</script>

<style lang="scss">
swiper{
	// width: 100%;
	height: 340rpx;
	.swiper-item,image{
		width: 100%;
		height: 100%;
	}
}
.nav-list {
	display: flex;
	justify-content: space-around;
	margin: 30rpx 0;
	.nav-item {
		width: 130rpx;
		height: 140rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
}
.floor-list {
	.floor-item {
		margin-left: 10rpx;
		margin-bottom: 10rpx;
		.floor-item-title{
			width: 100%;
			height: 60rpx;
		}
		.floor-img-box {
			display: flex;
			height: 400rpx;
			.left-img-box {
				width: 33%;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.right-img-box {
				width: 66%;
				display: flex;
				flex-wrap: wrap;
				.right-img-item {
					width: 48%;
					.right-item-img {
						width: 100%;
						height: 100%; 
					}
				}
			}
		}
		
	}
}
</style>